const ws = require('nodejs-websocket')

let server = null
let io = null

const clients = []

function sendAll(text) {
  this.connections.forEach((connect)=> {
    connect.send(text)
  })
}

function createdHMRServer(port) {
  const server = ws.createServer(conn => {
    clients.push(conn.socket)
  })

  return {
    listen: server.listen.bind(server, port),
    clients,
    sendAll: sendAll.bind(server)
  }
}

module.exports = {
  createdHMRServer
}
